{extend name="$BASE_POPUP_FORM" /}
{block name="body"}
<style>
    .edui-editor, .edui-editor-iframeholder {
        width: 530px !important;
    }
    .left-float{float: left;}
</style>
<div class="box-content">
    <input type="hidden" id="id" name="id" value="{$id}"/>
    <div class="control-row col-2">
        <div class="control-group">
            <label class="control-label">视频类型</label>
            <div class="controls">
                <select name="video_type" id="video_type" class="form-control required">
                    <option value="">选择分类</option>
                    <option value="0">短视频</option>
                    <option value="1">影片</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">短视频分类</label>
            <div class="controls">
                <select name="class_id_s" id="class_id_s" class="form-control required">
                    <option value="">选择分类</option>
                    {volist name="class_list" id="vo"}
                    <option value="{$vo.id}">{$vo.class_title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">影片分类</label>
            <div class="controls">
                <select name="class_id_f" id="class_id_f" class="form-control ">
                    <option value="">选择分类</option>
                    {volist name="class_list_f" id="vo"}
                    <option value="{$vo.id}">{$vo.class_title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">视频标题</label>
            <div class="controls">
                <input type="text" id="video_title" name="video_title" class="form-control required" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">发布人</label>
            <div class="controls">
                <input id="user_id" name="user_id" data-ui="combosearch" data-options="{valueField:'id',textField:'username',showList:true,matchFields:['username'],data:user_data,searchWin:openSearchWin}"
                       class="form-control"/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">是否免费</label>
            <div class="controls">
                <select name="is_free" id="is_free" class="form-control">
                    <option value="0">是</option>
                    <option value="1">否</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">购买金额</label>
            <div class="controls">
                <input type="text" id="need_amount" name="need_amount" value="0" class="form-control required" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">是否发布</label>
            <div class="controls">
                <select name="is_public" id="is_public" class="form-control">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>
        <!-- <div class="control-group">
            <label class="control-label">是否热门</label>
            <div class="controls">
                <select name="is_hot" id="is_hot" class="form-control">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div> -->
    </div>
    <div class="control-group">
        <label class="control-label">选择标签</label>
        <div class="controls">
            {volist name="tags_list" id="vo"}
            <div class="layui-form-item left-float">
                <label class="layui-form-label">{$vo.tags_name}</label>
                <div class="layui-input-block">
                    <input class="property" type="checkbox" name="tags[]" lay-skin="switch" value="{$vo.id}">
                </div>
            </div>
            {/volist}
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">设置方式</label>
        <div class="controls">
            <select name="set_type" id="set_type" class="form-control">
                <option value="0">上传</option>
                <option value="1">手动填写</option>
            </select>
        </div>
    </div>
    <div id="text-input" style="display: none">
        <div class="control-group">
            <label class="control-label">视频封面</label>
            <div class="controls">
                <input style="width: 600px" type="text" id="video_img_t" name="video_img_t" value="0" class="form-control " />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">视频地址</label>
            <div class="controls">
                <input style="width: 600px" type="text" id="video_path_t" name="video_path_t" value="" class="form-control "  />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">视频时长</label>
            <div class="controls">
                <input type="text" id="video_length_t" name="video_length_t" value="0" class="form-control " />
                <video style="display:none;" controls="controls" id="aa_video" ></video>
                <input type="button" name="" class="form-control" onclick="doDuration()" value="获取时长">
            </div>
        </div>
    </div>
    <div class="control-group file-input" >
        <label class="control-label">
            视频封面
        </label>
        <div class="controls">
            <div id="js_upload_wrp">
                <input type="hidden" id="video_img" name="video_img" value="" class="" />
                {:hook('picResource',array('name'=>'video_img','folder'=>'video_cover','tips'=>'建议尺寸：750x240像素。仅支持.jpg .png格式长方形照片。','callback'=>'uploadImgCallback'))}
            </div>
        </div>
    </div>
    <div class="control-group video_url_div file-input" style="">
        <label class="control-label">
            视频
        </label>
        <div class="controls">
            <div id="">
                <input type="hidden" id="video_length" name="video_length" value="" class="" />
                <input type="hidden" id="video_path" name="video_path" value="" class="" />
                {:hook('videoResource',array('name'=>'video_path','folder'=>'video_cover','tips'=>'建议上传正确的视频。','callback'=>'uploadVideoCallback'))}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    var user_data ={$user_list};
    var counter = 0;
    function openSearchWin(){
        var url = getURL('member/select_user','is_actor=1','member');
        openBarWinParent('选择用户', 500, 600, url, function (data) {
            $("#user_id").setValue(data);
        }, ['选定', '取消']);
    }

    function onLoadDataSuccess(data){
        console.log(data)
        // onLoadSuccess(data);
        setPicValue("video_img", data['video_img']);
        setVideoValue('video_path',data['video_path'])
        if(data['tags']){
            $(".property").each(function(){
                var val = $(this).val();
                if($.inArray( val, data['tags'] ) != -1){
                    $(this).attr("checked","checked")
                }
            })
            $(".ui-form").ui().render();
        }
    }
    function uploadImgCallback(path) {
        $("#video_img").val(path);
    }
    function uploadVideoCallback(path) {
        console.log(path[0]);
        $("#video_path").val(path[0].path);
        $("#video_length").val(path[0].length);
        setVideoValue('video_path',path[0].path)
    }
    $("#video_type").change(function(){
        var val = $(this).val();
        if(val==0){
            $('#class_id_s').parent().parent().show();
            $('#class_id_f').parent().parent().hide();
            $('#class_id_s').addClass('required');
            $('#class_id_f').removeClass('required');
        }else{
            $('#class_id_s').parent().parent().hide();
            $('#class_id_f').parent().parent().show();
            $('#class_id_f').addClass('required');
            $('#class_id_s').removeClass('required');

        }
    })

    $("#set_type").change(function(){
        var val = $(this).val();
        if(val==0){
            $('#text-input').hide();
            $('.file-input').show();
        }else{
            $('#text-input').show();
            $('.file-input').hide();
        }
    })


    function chkForm(){
        return true;
    }

    $("#video_path_t").change(function(){
        var addr = $(this).val();
        $('#aa_video').attr('src',addr);
        var vid = document.getElementById("aa_video");
        vid.onloadedmetadata = function() {
            document.getElementById("video_length_t").value=vid.duration;
        };
    })
    
    function doDuration(){
        var addr = $('#video_path_t').val();
        $('#aa_video').attr('src',addr);
        var vid = document.getElementById("aa_video");
        vid.onloadedmetadata = function() {
            console.log('metadata loaded!');
            document.getElementById("video_length_t").value=vid.duration;
        };
        return true;
    }


</script>
{/block}
